package com.javaee.wordtree.config;

import com.javaee.wordtree.service.StoryAutoGenerationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@EnableScheduling
@Slf4j
public class ScheduleConfig {
    
    @Resource
    private StoryAutoGenerationService storyAutoGenerationService;
    
    /**
     * 每天凌晨2点为系统预生成通用故事
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void generateCommonStories() {
        log.info("开始生成通用故事模板");
        // 使用常用单词生成通用故事
        storyAutoGenerationService.generateStoriesForUser("system");
    }
}